//
//  AppDelegate.m
//  WildDonkey
//
//  Created by 佟小波 on 15/3/27.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "AppDelegate.h"
#import "TravelTableViewController.h"
//#import "EntertainmentTableViewController.h"
#import "ImageTableViewController.h"
#import "JourneyTableViewController.h"
#import "LBSTableViewController.h"
#import "MyTableViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "Reachability.h"
#import "DDMenuController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [super dealloc];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    
    
    TravelTableViewController *travelVC = [[TravelTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    UINavigationController *travelNavC = [[UINavigationController alloc] initWithRootViewController:travelVC];
    travelNavC.tabBarItem.title = @"趣旅游";
    travelNavC.tabBarItem.image =[UIImage imageNamed:@"poi_des"];
    
    
    
    ImageTableViewController *entertainVC = [[ImageTableViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *entertainNavC = [[UINavigationController alloc] initWithRootViewController:entertainVC];
    entertainNavC.tabBarItem.title = @"趣乐事";
    entertainNavC.tabBarItem.image=[UIImage imageNamed:@"man"];
    
    JourneyTableViewController *journeyVC = [[JourneyTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    UINavigationController *journeyNavC = [[UINavigationController alloc] initWithRootViewController:journeyVC];
    journeyNavC.tabBarItem.title = @"游记";
    journeyNavC.tabBarItem.image=[UIImage imageNamed:@"poi"];
    
    
    LBSTableViewController *lbsVC = [[LBSTableViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *lbsNC = [[UINavigationController alloc] initWithRootViewController:lbsVC];
    lbsNC.tabBarItem.title = @"周边";
    lbsNC.tabBarItem.image = [UIImage imageNamed:@"poi"];
	
	MyTableViewController *MyVC = [[MyTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
	UINavigationController *MyNC = [[UINavigationController alloc] initWithRootViewController:MyVC];
	MyNC.tabBarItem.title = @"我的";
	MyNC.tabBarItem.image = [UIImage imageNamed:@"pic_gone"];
	
	
    UITabBarController *tabBarC = [[UITabBarController alloc] init];
    tabBarC.viewControllers = @[travelNavC,entertainNavC,journeyNavC,MyNC];
    self.window.rootViewController = tabBarC;
    
    [tabBarC release];
    
    [travelNavC release];
    [entertainNavC release];
    [journeyNavC release];
    
    [travelVC release];
    [entertainVC release];
    [journeyVC release];

    [self.window makeKeyAndVisible];
    
    // 监测网络情况
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reachabilityChanged:)
                                                 name: kReachabilityChangedNotification
                                               object: nil];
    hostReach = [[Reachability reachabilityWithHostName:@"api.smzdm.com"] retain];
    
    [hostReach startNotifier];  //开始监听,会启动一个run loop
    
    
    return YES;
    
    
    
    
    
    return YES;
}


#pragma  mark   当网络连接中断时，会调用此方法
- (void)reachabilityChanged:(NSNotification *)note {
    
    Reachability* curReach = [note object];
    NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
    NetworkStatus status = [curReach currentReachabilityStatus];
    
    if (status == NotReachable) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                        message:@"网络不可用,请检查网络连接"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
